package com.zhhh.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.wordnik.swagger.annotations.ApiOperation;
import com.zhhh.domain.Test;
import com.zhhh.model.ResultModel;
import com.zhhh.repository.TestRepository;


/**
 * ${comments}
 *
 * @author 管跃云
 * @email 401946949@qq.com
 * @date 2019-12-20 18:28:25
 */
@RestController
@RequestMapping("/Test")
public class TestController {

	@Autowired
	private TestRepository testRepository;

	@ResponseBody
	@RequestMapping(value = "/queryTestAll", method = RequestMethod.POST)
	@ApiOperation(value = "查询所有${comments}清单")
	public ResponseEntity<List<Test>> queryTestAll() {
		List<Test> findAll = (List<Test>)testRepository.findAll();
		return new ResponseEntity<>(findAll, HttpStatus.OK);
	}

	@RequestMapping(value = "/deleteTest", method = RequestMethod.POST)
	@ApiOperation(value = "删除${comments}")
	public ResponseEntity<ResultModel> deleteTest(@RequestParam Integer id) {
		testRepository.deleteById(id);
		List<Test> findAll = (List<Test>) testRepository.findAll();
		return new ResponseEntity<>(ResultModel.ok(findAll), HttpStatus.OK);
	}

	@RequestMapping(value = "/updateTest", method = RequestMethod.POST)
	@ApiOperation(value = "增加或者修改模块")
	public ResponseEntity<ResultModel> updateTest(@ModelAttribute("test") Test test) {
		testRepository.save(test);
		List<Test> findAll = (List<Test>) testRepository.findAll();
		return new ResponseEntity<>(ResultModel.ok(findAll), HttpStatus.OK);
	}

}
